﻿namespace UnityEditor
{
    using System;
    using UnityEngine;

    internal class RotateTool
    {
        public static void OnGUI()
        {
            if ((Selection.activeTransform != null) && !Tools.s_Hidden)
            {
                Undo.SetSnapshotTarget(Selection.transforms, "Rotate " + ((Selection.transforms.Length != 1) ? string.Empty : Selection.activeGameObject.name));
                Vector3 handlePosition = Tools.handlePosition;
                Quaternion handleRotation = Tools.handleRotation;
                Quaternion quaternion2 = Handles.RotationHandle(handleRotation, handlePosition);
                if (GUI.changed)
                {
                    float num;
                    Vector3 vector2;
                    (Quaternion.Inverse(handleRotation) * quaternion2).ToAngleAxis(out num, out vector2);
                    vector2 = (Vector3) (handleRotation * vector2);
                    foreach (Transform transform in Selection.transforms)
                    {
                        transform.RotateAround(handlePosition, vector2, num);
                        if (transform.parent != null)
                        {
                            transform.SendTransformChangedScale();
                        }
                    }
                    Tools.handleRotation = quaternion2;
                }
            }
        }
    }
}

